# syntax=docker/dockerfile:experimental
FROM gradle:7.4.2-jdk17-alpine as build-stage
WORKDIR /app
ENV GRADLE_USER_HOME=~/.gradle
COPY . .
RUN --mount=target=${GRADLE_USER_HOME},type=cache \
    gradle clean build -x test --no-daemon

FROM registry.access.redhat.com/ubi8/openjdk-17:1.11
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'

# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --from=build-stage --chown=185 /app/app/build/quarkus-app/lib/ /deployments/lib/
COPY --from=build-stage --chown=185 /app/app/build/quarkus-app/*.jar /deployments/
COPY --from=build-stage --chown=185 /app/app/build/quarkus-app/app/ /deployments/app/
COPY --from=build-stage --chown=185 /app/app/build/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
USER 185
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"